package com.sxkj.web.controller.api;

import com.sxkj.common.response.ResponseResult;
import com.sxkj.entity.entity.version.Version;
import com.sxkj.entity.entity.version.VersionScaleRecord;
import com.sxkj.service.version.VersionScaleRecordService;
import com.sxkj.service.version.VersionScaleService;
import com.sxkj.service.version.VersionService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Zhang Xingliang
 * @description 查询客户端更新版本信息(摊床)
 * @date 11:28 2019/11/2
 **/
@RestController
@RequestMapping("/api/version")
public class VersionApiController {

    @Autowired
    private VersionService versionService;
    @Autowired
    private VersionScaleRecordService versionScaleRecordService;

    /**
     * @author Zhang Xingliang
     * @description 获取客户端能更新的最新版本信息
     * @date 13:02 2019/11/2
     * @param version
     * @return java.lang.Object
     **/

    @RequestMapping(value = "/info", method = RequestMethod.POST)
    public ResponseResult searchVersion(@RequestBody Version version) {
        try {
			List<Map<String,String>> result = versionService.findNewVersion(version);
            return ResponseResult.success(result);
        } catch (Exception e) {
            return ResponseResult.failure(e.toString());
        }
    }

    /**
     * @author Zhang Xingliang
     * @description 更新秤端更新下载文件的状态
     * @date 15:18 2019/11/7
     * @param versionScaleRecord
     * @return java.lang.Object
     **/
    @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
    public Object updateStatus(@RequestBody VersionScaleRecord versionScaleRecord) {
        try {
            versionScaleRecordService.updateVersionScaleRecord(versionScaleRecord);
            return ResponseResult.success();
        } catch (Exception e) {
            return ResponseResult.failure(e.toString());
        }
    }

}
